package com.zmj.sy.mom.srv.aps.controller;

import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseIdReqVo;
import com.zmj.sy.mom.srv.aps.bean.vo.base.Result;
import com.zmj.sy.mom.srv.aps.bean.vo.dictdata.*;
import com.zmj.sy.mom.srv.aps.config.AspectLog;
import com.zmj.sy.mom.srv.aps.service.DictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequiredArgsConstructor
@Api(tags = "字典项管理")
@RestController
@RequestMapping("/dictData")
public class DictDataController {

    private final DictDataService dictDataService;

    @PostMapping("/add")
    @ApiOperation("根据字典类型新增字典项")
    public Result<String> add(@RequestBody DictDataAddReqVo reqVo) {
        dictDataService.add(reqVo);
        return Result.success();
    }

    @PostMapping("/edit")
    @ApiOperation("编辑字典项")
    @AspectLog(apiName = "编辑字典项", operationType = 4)
    public Result<String> edit(@RequestBody DictDataEditReqVo reqVo) {
        dictDataService.edit(reqVo);
        return Result.success();
    }

    @PostMapping("/delete")
    @ApiOperation("删除字典项")
    @AspectLog(apiName = "删除字典项", operationType = 4)
    public Result<String> delete(@RequestBody BaseIdReqVo reqVo) {
        dictDataService.delete(reqVo);
        return Result.success();
    }


    @GetMapping("/get")
    @ApiOperation("通过ID查询字典项")
    public Result<DictDataGetResVo> get(BaseIdReqVo reqVo) {
        DictDataGetResVo d = dictDataService.get(reqVo);
        return Result.success(d);
    }

    @GetMapping("/find")
    @ApiOperation("通过类型的code查询字典项")
    public Result<List<DictDataFindResVo>> find(DictDataFindReqVo reqVo) {
        List<DictDataFindResVo> dictDataFindResVos = dictDataService.find(reqVo);
        return Result.success(dictDataFindResVos);
    }


}
